home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / mtgrap1c / demo8.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-13  |  12.3 KB  |  299 lines

  1. /*                                                            
  2.   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  3.   ▒                                                          ▒
  4.   ▒                                                          ▒
  5.   ▒             Neuromancer's Graphics Library               ▒
  6.   ▒                     Version 1.0c                         ▒
  7.   ▒                                                          ▒ 
  8.   ▒    This program illustrates yet another method for       ▒ 
  9.   ▒    animation. In this case, dirtied rectangles           ▒ 
  10.   ▒    are flipped to the active pages. This is more         ▒ 
  11.   ▒    elaborate but the effect is much smoother.            ▒       
  12.   ▒    Alternatively, to avoid doing dirty rectangles        ▒       
  13.   ▒    technique when transferring to the video memory,      ▒           
  14.   ▒    copy the entire page (PAGE_1) to the video buffer.    ▒         
  15.   ▒                                                          ▒       
  16.   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  17.   ▒                                                          ▒
  18.   ▒     Project:    MTLIB01.LIB                              ▒
  19.   ▒                 DEMO8.CPP                                ▒
  20.   ▒                                                          ▒ 
  21.   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  22. */
  23.  
  24. #include <iostream.h>
  25. #include <stdlib.h>
  26. #include <conio.h>
  27. #include "video.h"
  28. #include <dos.h>
  29. #include "bitmap.h"
  30.  
  31. byte sprite1[]={
  32.   /*23,29,*/
  33.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.   0, 0, 0, 0, 0, 0, 0, 0, 0,42,42,42,42,42, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.   0, 0, 0, 0, 0, 0, 0,42,42,42,42,42,42,42,42,42, 0, 0, 0, 0, 0, 0, 0,
  36.   0, 0, 0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42, 0, 0, 0, 0, 0, 0,
  37.   0, 0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42, 0, 0, 0, 0, 0,
  38.   0, 0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42, 0, 0, 0, 0, 0,
  39.   0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42,12,40, 0, 0, 0, 0,
  40.   0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42,41,40, 0, 0, 0, 0,
  41.   0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42,40,40, 0, 0, 0, 0,
  42.   0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42,40,40, 0, 0, 0, 0,
  43.   0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,42,42,40,40, 0, 0, 0, 0,
  44.   0, 0, 0, 0, 0,42,42,42,42,42,42,42,42,42,42,42,12,40, 0, 0, 0, 0, 0,
  45.   0, 0, 0, 0, 0,41,42,42,42,42,42,42,42,42,42,42,40,40, 0, 0, 0, 0, 0,
  46.   0, 0, 0, 0, 0, 0,41,42,42,42,42,42,42,42,42,40,40, 0, 0, 0, 0, 0, 0,
  47.   0, 0, 0, 0, 0, 0, 0,41,41,42,42,42,42,12,40,40, 0, 0, 0, 0, 0, 0, 0,
  48.   0, 0, 0, 0, 0, 0, 0, 0, 0,41,41,41,41,41, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  49.   0, 0, 0, 0, 0, 0, 0, 0, 0,30,29,27,25,24, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  50.   0, 0, 0, 0, 0, 0, 0, 0, 0,30,29,27,25,24, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  51.   0,46,45, 0, 0, 0, 0, 0, 0,30,29,27,25,24, 0, 0, 0, 0, 0, 0,46,44, 0,
  52.   0,46,45, 0, 0, 0, 0, 0, 0,30,29,27,25,24, 0, 0, 0, 0, 0, 0,46,44, 0,
  53.   0,46,45, 0, 0, 0, 0, 0,29,30,29,27,25,24,26, 0, 0, 0, 0, 0,46,44, 0,
  54.   0,46,45,44, 0, 0, 0,29,29,30,29,27,25,24,26,26, 0, 0, 0,46,46,44, 0,
  55.   0,46,45,44, 0, 0,29,29,29,30,29,27,25,24,26,26,26, 0, 0,46,46,44, 0,
  56.   0,46,45,44, 0,29,29,29,29,30,29,27,25,24,26,26,26,26, 0,46,46,44, 0,
  57.   0,46,45,44,29,29,29,29,29,30,29,27,25,24,25,26,26,26,26,46,46,44, 0,
  58.   0,46,45,44,29,29,29,29,29,30,29,27,25,24,25,25,25,26,26,46,46,44, 0,
  59.   0,46,45,44,29,29,29, 0, 0,30,29,27,25,24, 0, 0,25,25,26,46,46,44, 0,
  60.   0,46,45,44,29,29, 0, 0, 0,23,23,24,24,23, 0, 0, 0,25,25,46,46,44, 0,
  61.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  62. };
  63.  
  64. byte sprite2[] = {
  65.   /*20,20,*/
  66.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  67.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  68.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  69.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  70.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  71.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  72.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  73.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  74.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  75.  75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 75, 75,
  76.  75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 75, 75,
  77.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  78.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  79.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  80.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  81.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  82.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  83.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  84.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  85.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75
  86.  
  87. };
  88.  
  89. byte sprite3[]={
  90. //20,20
  91.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  92.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  93.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  94.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  95.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  96.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  97.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  98.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  99.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  100.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  101.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  102.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  103.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  104.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  105.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  106.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  107.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  108.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  109.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  110.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75
  111. };
  112.  
  113. byte sprite4[]={
  114. //20,20
  115.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  116.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  117.  75, 75, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  118.  75, 75, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  119.  75, 75, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  120.  75, 75, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  121.  75, 75, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  122.  75, 75, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  123.  75, 75, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  124.  75, 75, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  125.  75, 75, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  126.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 75, 75,
  127.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 75, 75,
  128.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 75, 75,
  129.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 75, 75,
  130.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 75, 75,
  131.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 75, 75,
  132.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 75, 75,
  133.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  134.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75
  135. };
  136.  
  137.  
  138. byte sprite5[]={
  139. //20,20
  140.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  141.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  142.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 75, 75,
  143.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 75, 75,
  144.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 75, 75,
  145.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 75, 75,
  146.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 75, 75,
  147.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 75, 75,
  148.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 75, 75,
  149.  75, 75, 45, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 75, 75,
  150.  75, 75, 45, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 75, 75,
  151.  75, 75, 45, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  152.  75, 75, 45, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  153.  75, 75, 45, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  154.  75, 75, 45, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  155.  75, 75, 45, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  156.  75, 75, 45, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  157.  75, 75, 80, 80, 80, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 75, 75,
  158.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  159.  75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75
  160. };
  161.  
  162. block page1,page2;
  163.  
  164. void main(void)
  165. {
  166.  
  167.     int xcor;    
  168.     int ycor;
  169.     
  170.     int xcor1;
  171.     int ycor1;
  172.  
  173.     int xdir;
  174.     int ydir;
  175.  
  176.     int xdir1;
  177.     int ydir1;
  178.  
  179.     int flag=0;
  180.     int inc=0;
  181.  
  182.     mtSetVGAMode();            //Set up VGA Mode
  183.     mtClrScr(25);
  184.  
  185.  
  186.     if ((page1=mtAllocPage(0,0,319,199))==NULL)
  187.     {
  188.         mtSetTextMode();
  189.         cout << "Error setting up Page1"<<endl;
  190.         exit(0);
  191.     }
  192.  
  193.     if ((page2=mtAllocPage(0,0,319,199))==NULL)
  194.     {
  195.         mtFreePage(PAGE_1);
  196.         mtSetTextMode();
  197.         cout << "Error setting up Page2"<<endl;
  198.         exit(0);
  199.     }
  200.  
  201.     //typically, this is the hidden screen where you would download
  202.     //your static background
  203.     mtSetPage(PAGE_1);
  204.     mtClrScr(25);
  205.  
  206.     mtSetPage(PAGE_2);
  207.     mtClrScr(25);
  208.  
  209.     xcor = random(297);
  210.     ycor = 150;
  211.     xcor1 =random(300);
  212.     ycor1 =30;
  213.  
  214.     xdir =5;
  215.     ydir =5;
  216.     xdir1=5;
  217.     ydir1=5;
  218.     flag=0;
  219.     inc=0;
  220.  
  221.     mtSetPage(PAGE_1);
  222.     
  223.     while(!kbhit())
  224.     {
  225.  
  226.         xcor += xdir;
  227.         xcor1 += xdir1;
  228.  
  229.         if (xcor < 0 || xcor > 297 ) {
  230.             xdir = -xdir;
  231.             xcor += xdir;
  232.         }
  233.  
  234.         if (xcor1<0||xcor1 >300) {
  235.             xdir1 = -xdir1;
  236.             xcor1 += xdir1;
  237.         }
  238.         
  239.         mtCPutBlit(xcor, ycor, 23, 29, sprite1);        //copy mode
  240.         if (flag ==0){
  241.             mtCPutSprite(xcor1, ycor1, 20, 20, sprite2);    //sprite mode
  242.             inc++;
  243.             if (inc == 1) flag = 1;
  244.         }
  245.         else
  246.         if (flag==1)
  247.         {
  248.             mtCPutSprite(xcor1, ycor1, 20, 20, sprite4);    //sprite mode
  249.             inc++;
  250.             if (inc==2) flag=2;
  251.         }
  252.         else
  253.         if (flag==2)
  254.         {
  255.             mtCPutSprite(xcor1, ycor1, 20, 20, sprite3);    //sprite mode
  256.             inc++;
  257.             if (inc==3) flag=3;
  258.         }
  259.         else
  260.         if (flag==3)
  261.         {    
  262.             mtCPutSprite(xcor1, ycor1, 20, 20, sprite5);    //sprite mode
  263.             inc++;
  264.             if (inc==4)
  265.             {
  266.              flag=0;
  267.              inc=0;
  268.             }
  269.         }
  270.         mtWaitRetrace();
  271.  
  272.         //using dirtied rectangles
  273.         mtCopyBlk(xcor-5,ycor-5,xcor+28, ycor+34, xcor-5,ycor-5,PAGE_1,PAGE_0);
  274.         mtCopyBlk(xcor1-5,ycor1-5,xcor1+25,ycor1+25,xcor1-5,ycor1-5,PAGE_1,PAGE_0);
  275.  
  276.         mtCopyBlk(xcor,ycor,xcor+23, ycor+29, xcor,ycor,PAGE_2,PAGE_1);
  277.         mtCopyBlk(xcor1,ycor1,xcor1+20,ycor1+20,xcor1,ycor1,PAGE_2,PAGE_1);
  278.     }
  279.  
  280.     getch();
  281.  
  282.     mtFreePage(PAGE_1);
  283.     mtFreePage(PAGE_2);
  284.  
  285.     mtSetTextMode();
  286.  
  287.     cout << "Thank you for using the library!" << endl;
  288.  
  289.     exit(0);
  290.     
  291. }
  292.  
  293.            
  294.             
  295.  
  296.            
  297.  
  298.            
  299.